﻿/*
 * NetMessageDef.h
 */
#include <gdk/core/Types.h>
#include <gdk/core/Message.h>
#include <gdk/core/Uuid.h>
#include <gdk/net/NetAddress.h>


namespace gdk
{


//**************************************************
#undef DECLARE_NET_MESSAGE_BEGIN
#undef DECLARE_NET_MESSAGE_MEMBER
#undef DECLARE_NET_MESSAGE_INIT
#undef DECLARE_NET_MESSAGE_END


//**************************************************
#if defined(IMPLEMENT_NET_MESSAGE_MTBL)

#	define DECLARE_NET_MESSAGE_BEGIN(className, baseClass) \
			IMPLEMENT_RT_CREATOR(className)\
			IMPLEMENT_MTBL_BEGIN(className)\
			IMPLEMENT_MTBL_SUPPER(baseClass)

#	define DECLARE_NET_MESSAGE_MEMBER(type, name) \
			IMPLEMENT_MTBL_MEMBER(name)

#	define DECLARE_NET_MESSAGE_INIT(name, value)

#	define DECLARE_NET_MESSAGE_END() \
			IMPLEMENT_MTBL_END()


//**************************************************
#elif defined(IMPLEMENT_NET_MESSAGE_PROPERTY)

#	define DECLARE_NET_MESSAGE_BEGIN(className, baseClass) \
			REGISTER_PROPERTY_CONVERTER_OBJECT(className)\
			IMPLEMENT_PROPERTY_BEGIN1(className, baseClass)

#	define DECLARE_NET_MESSAGE_MEMBER(type, name) \
			IMPLEMENT_PROPERTY_ATTRIBUTE(name, __TEXT__(#name))

#	define DECLARE_NET_MESSAGE_INIT(name, value)

#	define DECLARE_NET_MESSAGE_END() \
			IMPLEMENT_PROPERTY_END()


//**************************************************
#elif defined(IMPLEMENT_NET_MESSAGE_INIT)

#	define DECLARE_NET_MESSAGE_BEGIN(className, baseClass) \
			className::className(void)\
				: baseClass()

#	define DECLARE_NET_MESSAGE_MEMBER(type, name) 

#	define DECLARE_NET_MESSAGE_INIT(name, value) \
				, name(value)

#	define DECLARE_NET_MESSAGE_END() \
			{}


//**************************************************
#elif defined(REGISTER_NET_MESSAGE)

#	define DECLARE_NET_MESSAGE_BEGIN(className, baseClass) \
			REGISTER_RT_CREATOR(className)\
			REGISTER_PROPERTY(className)

#	define DECLARE_NET_MESSAGE_MEMBER(type, name) 

#	define DECLARE_NET_MESSAGE_INIT(name, value)

#	define DECLARE_NET_MESSAGE_END() 


//**************************************************
#else


	//---------------------------------------------
#	define DECLARE_NET_MESSAGE_BEGIN(className,baseClass) \
			typedef gdk::Unknown::Handle_T<class className> className##Ptr;\
			class GDK_NET_EXPORT className : public baseClass\
			{\
				DECLARE_CLASS_HANDLE(className)\
				DECLARE_CLASS_INSTANCE(className)\
				DECLARE_CLASS_SERIALIZE(className)\
				DECLARE_RT_CREATOR(className)\
				DECLARE_PROPERTY(className)\
				DECLARE_MTBL(className)\
				DECLARE_MESSAGE_PARSE(className)\
			private:\
				className(void);\
			public:

#	define DECLARE_NET_MESSAGE_MEMBER(type, name) \
				type name;

#	define DECLARE_NET_MESSAGE_END() \
			};


//**************************************************
#endif


//=====================================================
DECLARE_NET_MESSAGE_BEGIN(NetStart, Message) //服务端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, socketId)
	DECLARE_NET_MESSAGE_MEMBER(uint16_t, port)
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetShutdown, Message) //服务端触发
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetAccept, Message) //服务端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, clientId)
	DECLARE_NET_MESSAGE_MEMBER(NetAddress, addr)
	DECLARE_NET_MESSAGE_MEMBER(Uuid, peerSocketId)
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetConnect, Message) //客户端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, clientId)
	DECLARE_NET_MESSAGE_MEMBER(NetAddress, addr)
	DECLARE_NET_MESSAGE_MEMBER(Uuid, peerSocketId)
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetConnectOk, Message) //服务端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, clientId)
	DECLARE_NET_MESSAGE_MEMBER(Uuid, peerSocketId)
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetConnectFail, Message) //服务端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, clientId)
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetBlocking, Message) //服务端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, clientId)
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetRestored, Message) //服务端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, clientId)
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetClose, Message) //客户端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, clientId)
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetAbort, Message) //服务端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, clientId)
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetError, Message) //服务端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, clientId)
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetClosed, Message) //服务端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, clientId)
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetSend, Message) //客户端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, clientId)
	DECLARE_NET_MESSAGE_MEMBER(Message::Handle, msg)
DECLARE_NET_MESSAGE_END()

DECLARE_NET_MESSAGE_BEGIN(NetReceive, Message) //服务端触发
	DECLARE_NET_MESSAGE_MEMBER(Uuid, clientId)
	DECLARE_NET_MESSAGE_MEMBER(Message::Handle, msg)
DECLARE_NET_MESSAGE_END()




} //namespace gdk

